﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public partial class FormAlongWallDraw : System.Windows.Forms.Form
	{
		public FormAlongWallDraw()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.AlongWallInitParameterSetting();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.CheckingTxtBoxDisText())
			{
				this.disToWall = Convert.ToDouble(this.txtBoxAloWallDis.Text.Trim());
				this.AlongWallUserSettingWrite();
				base.DialogResult = DialogResult.OK;
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void rbtnOutline_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbtnOutline.Checked)
			{
				this.pipeDisType = AlongWallDisType.PipeOutline;
			}
		}

		private void rbtnPipeCentre_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rbtnPipeCentre.Checked)
			{
				this.pipeDisType = AlongWallDisType.PipeCentre;
			}
		}

		public AlongWallDisType PipeDisType
		{
			get
			{
				return this.pipeDisType;
			}
		}

		public double DisToWall
		{
			get
			{
				return this.disToWall;
			}
		}

		private void AlongWallInitParameterSetting()
		{
			try
			{
				this.txtBoxAloWallDis.Text = ClassMultiPipeXMLInfo.GetSelectSingleNodeValue(FormAlongWallDraw.path, "nodeAlongWall/alongWallDis");
				this.pipeDisType = (AlongWallDisType)Convert.ToInt32(ClassMultiPipeXMLInfo.GetSelectSingleNodeValue(FormAlongWallDraw.path, "nodeAlongWall/distanceType"));
				if (this.pipeDisType == AlongWallDisType.PipeCentre)
				{
					this.rbtnPipeCentre.Checked = true;
					this.rbtnOutline.Checked = false;
				}
				if (this.pipeDisType == AlongWallDisType.PipeOutline)
				{
					this.rbtnOutline.Checked = true;
					this.rbtnPipeCentre.Checked = false;
				}
			}
			catch (Exception)
			{
			}
		}

		private void AlongWallUserSettingWrite()
		{
			try
			{
				ClassMultiPipeXMLInfo.UpdateSelectSingleNodeValue(FormAlongWallDraw.path, "nodeAlongWall/alongWallDis", this.txtBoxAloWallDis.Text);
				string text = FormAlongWallDraw.path;
				string selectSingleNodeName = "nodeAlongWall/distanceType";
				int num = (int)this.pipeDisType;
				ClassMultiPipeXMLInfo.UpdateSelectSingleNodeValue(text, selectSingleNodeName, num.ToString());
			}
			catch (Exception)
			{
			}
		}

		private bool CheckingTxtBoxDisText()
		{
			bool result = true;
			if (!this.regex.IsMatch(this.txtBoxAloWallDis.Text.Trim()))
			{
				result = false;
				this.txtBoxAloWallDis.Focus();
				YJKMessageBox.Show("输入数字格式不正确,应为正负整数或小数，且不能为空！");
			}
			return result;
		}

		public static string path = Path.Combine(Product.DataLocation, "HYDrawParallelPipeInfo.xml");

		private AlongWallDisType pipeDisType;

		private double disToWall;

		private Regex regex = new Regex("^[+-]?[0-9]+\\d*[.]?\\d*$");
	}
}
